package cn.edu.scau.cmi.suyaoxing.client;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import cn.edu.scau.cmi.suyaoxing.spring.domain.*;
import cn.edu.scau.cmi.suyaoxing.spring.util.*;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class SpringClient extends Application{
	public static void main(String[] args) {
	       launch(args);
	    }
	ApplicationContext applicationContext=ApplicationContextUtil.getApplicationContet();
	private Student student=null;
	 public void start(Stage primaryStage) {
		   GridPane gridpane=new GridPane();
		   gridpane.setAlignment(Pos.CENTER);
	       TextField tf=new TextField();
	       TextArea ta=new TextArea();
	       Button bt=new Button("get Tutor");
	       Label lb=new Label("StudentId:");
	       
		   bt.setOnAction(new EventHandler<ActionEvent>() {
			  @Override
			  public void handle(ActionEvent event) {
				  student=(Student)applicationContext.getBean(tf.getText());
					  ta.setText("StudentName:"+student.getName()+"\n");
					  ta.appendText("TutorName:"+student.getTutor().getName()+"\n");
			  }
		   });
		   gridpane.add(lb, 0, 0,5,1);
		   gridpane.add(tf, 5, 0,10,1);
		   gridpane.add(bt, 15, 0,5,1);
		   gridpane.add(ta, 0, 1,25,10);
	       Scene scene=new Scene(gridpane,1100,500);
	       primaryStage.setTitle("实验八 Spring基本使用");
	       primaryStage.setScene(scene);
	       primaryStage.show();
	    }
}
